﻿using Castle.DynamicProxy;
using StructureMap;
using WS.EKA.Core.Interceptor;
using WS.EKA.ServiceInterface;

namespace WS.EKA.Core.DI
{
    public class ServiceFactory : IServiceFactory
    {
        private static readonly ProxyGenerator proxy = new ProxyGenerator();
        private static readonly IInterceptor handler = new DefaultInterceptor();

        private static readonly IContainer container = ServiceResolverFactory.CreateContiner();

        public T GetInterfaceImplement<T>() where T : class
        {
            T service = container.GetInstance<T>();
            return proxy.CreateInterfaceProxyWithTarget<T>(service, handler);
        }
    }
}
